<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%
String productId = request.getParameter("ID");

if (productId != null && !productId.isEmpty()) { // 检查productId是否为null或空字符串
    try {
        // 连接数据库的代码（与前面相同，略过）
        Connection connection = DriverManager.getConnection("jdbc:mariadb://10.220.140.102:3366/studb14", "stu14", "jyw745DJ");
        PreparedStatement pstmt = connection.prepareStatement("DELETE FROM dishes WHERE id = ?");
        
        pstmt.setInt(1, Integer.parseInt(productId));
        
        int result = pstmt.executeUpdate();
        
        if (result > 0) {
            // 删除成功
            out.println("<script>alert('删除成功!');location='菜品管理页面URL';</script>");
        } else {
            // 删除失败
            out.println("<script>alert('删除失败!');history.back();</script>");
        }
    } catch (Exception e) {
        e.printStackTrace();
        // 处理数据库操作异常
    }
} else {
    // 处理productId为空的情况，例如输出错误信息或者重定向到错误页面
    out.println("<script>alert('产品ID不能为空!');history.back();</script>");
}
%>
</body>
</html>